package com.whalehearing.tingyou.web.controller.hearing;

import com.whalehearing.tingyou.common.annotation.DataSource;
import com.whalehearing.tingyou.common.annotation.Log;
import com.whalehearing.tingyou.common.core.controller.BaseController;
import com.whalehearing.tingyou.common.core.domain.AjaxResult;
import com.whalehearing.tingyou.common.core.page.TableDataInfo;
import com.whalehearing.tingyou.common.enums.BusinessType;
import com.whalehearing.tingyou.common.enums.DataSourceType;
import com.whalehearing.tingyou.common.utils.poi.ExcelUtil;
import com.whalehearing.tingyou.domain.HearingTranslationRecord;
import com.whalehearing.tingyou.service.IHearingTranslationRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 语音转文字记录Controller
 *
 * @author zengjun-qxm
 * @date 2024-10-29
 */
@Api(tags = "语音转文字记录管理")
@RestController
@DataSource(DataSourceType.SLAVE)
@RequestMapping("system/hearing/record")
public class HearingTranslationRecordController extends BaseController {
    @Autowired
    private IHearingTranslationRecordService hearingTranslationRecordService;

    /**
     * 查询语音转文字记录列表
     */
    @ApiOperation("查询语音转文字记录列表")
    @PreAuthorize("@ss.hasPermi('hearing:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(HearingTranslationRecord hearingTranslationRecord) {
        startPage();
        List<HearingTranslationRecord> list = hearingTranslationRecordService.selectHearingTranslationRecordList(hearingTranslationRecord);
        return getDataTable(list);
    }

    /**
     * 导出语音转文字记录列表
     */
    @ApiOperation("导出语音转文字记录列表")
    @PreAuthorize("@ss.hasPermi('hearing:record:export')")
    @Log(title = "语音转文字记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HearingTranslationRecord hearingTranslationRecord) {
        List<HearingTranslationRecord> list = hearingTranslationRecordService.selectHearingTranslationRecordList(hearingTranslationRecord);
        ExcelUtil<HearingTranslationRecord> util = new ExcelUtil<HearingTranslationRecord>(HearingTranslationRecord.class);
        util.exportExcel(response, list, "语音转文字记录数据");
    }

    /**
     * 获取语音转文字记录详细信息
     */
    @ApiOperation("获取语音转文字记录详细信息")
    @PreAuthorize("@ss.hasPermi('hearing:record:query')")
    @GetMapping(value = "/{translationRecordId}")
    public AjaxResult getInfo(@PathVariable("translationRecordId") Long translationRecordId) {
        return success(hearingTranslationRecordService.getById(translationRecordId));
    }

    /**
     * 新增语音转文字记录
     */
    @ApiOperation("新增语音转文字记录")
    @PreAuthorize("@ss.hasPermi('hearing:record:add')")
    @Log(title = "语音转文字记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HearingTranslationRecord hearingTranslationRecord) {
        return toAjax(hearingTranslationRecordService.save(hearingTranslationRecord));
    }

    /**
     * 修改语音转文字记录
     */
    @ApiOperation("修改语音转文字记录")
    @PreAuthorize("@ss.hasPermi('hearing:record:edit')")
    @Log(title = "语音转文字记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HearingTranslationRecord hearingTranslationRecord) {
        return toAjax(hearingTranslationRecordService.updateById(hearingTranslationRecord));
    }

    /**
     * 删除语音转文字记录
     */
    @ApiOperation("删除语音转文字记录")
    @PreAuthorize("@ss.hasPermi('hearing:record:remove')")
    @Log(title = "语音转文字记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{translationRecordIds}")
    public AjaxResult remove(@PathVariable Long[] translationRecordIds) {
        return toAjax(hearingTranslationRecordService.removeByIds(Arrays.asList(translationRecordIds)));
    }
}
